/* QtLua -- Lua bindings for Qt
   Copyright (C) 2011, Jarek Pelczar

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library; if not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301 USA

*/

#ifndef QLUAENGINEGLOBALS_P_H
#define QLUAENGINEGLOBALS_P_H

#include <QtCore>
#include "../etc/lua.hpp"

class QLuaScriptEngine;
class QLuaScriptEnginePrivate;
class QLuaScriptConsoleInterface;

class QLuaEngineGlobals : public QObject
{
    Q_OBJECT
public:
    QLuaEngineGlobals();

    static QLuaEngineGlobals * get();

    QMutex m_lock;
    QHash<lua_State *, QLuaScriptEngine *> m_stateToEngine;
    QHash<lua_State *, QLuaScriptEnginePrivate *> m_stateToEngineImpl;
    QHash<QObject *, QLuaScriptEngine *> m_objectToEngine;
    QHash<lua_State *, QLuaScriptConsoleInterface *> m_debuggerConsoles;
    QStringList m_pluginImportPaths;

    static void registerEngine(lua_State * L, QLuaScriptEngine * engine, QLuaScriptEnginePrivate * d);
    static void unregisterEngine(lua_State * L);
    static void registerQObject(QObject * o, QLuaScriptEngine * engine);
    static QLuaScriptEngine * engineFromQObject(QObject * o);
    static QLuaScriptEngine * engineFromLua(lua_State * L);

    static void registerDebuggerConsole(QLuaScriptConsoleInterface *);
    static void unregisterDebuggerConsole(QLuaScriptConsoleInterface *);
    static QLuaScriptConsoleInterface * debuggerConsole(lua_State * L);

private slots:
    void object_destroyed(QObject * o);
};

#endif // QLUAENGINEGLOBALS_P_H
